import re, sys
from optparse import OptionParser

def gen_rand_view(num = 3, viewname = 'view'):
    view_len = len(str(num))
    return [viewname + "%.*d" % (view_len, i) for i in range(0, num)]

def write_viewlist_in(viewnum, outfile):
    viewlist = gen_rand_view(viewnum)
    fp = open(outfile, 'w')
    for viewname in viewlist:
        fp.write(viewname + '\n')
    fp.close()

def obtain_viewlist_from_file(view_file):
    fp = open(view_file)
    viewlist = []
    for view in fp.readlines():
        if re.match('^#', view) or re.match('^\s*$', view):
           continue
        viewlist.append(view.strip('\n'))
    fp.close()

    return viewlist

def getopt():
    parser = OptionParser()
    parser.add_option("-w", "--outfile", dest = "outfile")
    parser.add_option("-n", "--num", dest = "num", default = '1', type = int)
    (opts, args) = parser.parse_args()
    if opts.outfile == None:
        opts.print_help()
        sys.exit(1)
    return opts

if __name__ == "__main__":
    opts = getopt()
    write_viewlist_in(opts["num"], opts["outfile"])
